package com.chuangke.system.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.db.page.CkPageQuery;
import com.chuangke.common.http.HttpResult;
import com.chuangke.system.annotation.OptLogDoc;
import com.chuangke.system.entity.SysComment;
import com.chuangke.system.enums.LogOptType;
import com.chuangke.system.service.SysCommentService;

@RestController
@RequestMapping("comment")
public class SysCommentController {

	@Autowired
	private SysCommentService sysCommentService;

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/findpage")
	public HttpResult findPage(@RequestBody Map<String,Object> params) {
		return HttpResult.ok(sysCommentService.findByTopic(new CkPageQuery(params)));
	}
	
	@OptLogDoc(objId="#sysComment.topicId",name="评论了任务",optType=LogOptType.COMMENT)
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/save")
	public HttpResult save(@RequestBody SysComment sysComment) {
		sysCommentService.save(sysComment);
		return HttpResult.ok();
	}

}
